/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       army_list_window.h

	$Header: /game/army_list_window.h $

	$NoKeywords: $

 ************************************************************************/

#ifndef ARMY_LIST_WINDOW_H_INCLUDED
#define ARMY_LIST_WINDOW_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "army_array.h"
#include "army_array_ptr.h"
#include "bitmap_group_ptr.h"
#include "bitmap_layer_window_ptr.h"
#include "bitmap_layer_cache_window_ptr.h"
#include "game_window.h"
#include "handler.h"
#include "list_viewer.h"
#include "scrollbar_ptr.h"

#include <vector>
class t_army;
class t_bitmap_layer;
class t_button;

typedef t_handler_1<t_army*>	t_army_select_handler;
typedef t_handler_1<int>		t_army_list_window_limit_handler;

const int	k_army_list_window_at_top		= 0x1;
const int	k_army_list_window_at_bottom	= 0x2;

// ----------------------------------------------------------------------
// display a list of armies
// ----------------------------------------------------------------------
class t_army_list_window : public t_window, public t_list_viewer 
{
public:
	t_army_list_window( t_screen_rect const& rect, t_window* parent, bool hide_unused = true );
	virtual ~t_army_list_window();

	void         attach( t_scrollbar* scrollbar );
	virtual void detach();
	int			 get_num_rings();
	int			 get_num_armies();
	virtual void inserted( int index );
	void		 move_list( int step_size );
	t_army *	 move_selection( int step_size, bool wrap_selection = false );
	void         move_selection_over_sleepers( int step_size, bool wrap_selection = true );
	virtual void removed( int index );
	void		 set_army_array( t_army_array* list );
	void         set_select_handler( t_army_select_handler handler );
	void		 set_limit_handler( t_army_list_window_limit_handler handler );
	void         set_double_click_handler( t_army_select_handler handler );
	void         select_army( t_army* army );
	void		 update();
    
    enum {
        k_maximum_army_value = 18000,
        k_minimum_army_value = 100,
        k_log_multiplier = 1000,
    };

protected:
	void			add_item( t_screen_point point, t_bitmap_layer const* move_bar,
						       t_bitmap_layer const* strength_bar,
							   t_screen_point portrait_point,
						       t_bitmap_layer const* frame, 
						       t_bitmap_layer const* frame_highlight,
							   t_bitmap_layer const* empty_background );
					
	void			double_click( t_button* button, int result );
	int				get_max_index();
	void			set_first_visible( int index );
	void			select( t_button* button, int result );
	void			set_scrollbar();
	void			set_highlight( int index );
	void			on_scroll( t_scrollbar* scrollbar, int first_value );
	virtual void	on_visibility_change();

	struct t_item
	{
		t_army*							army;
		t_button*                       button;
		t_window_ptr					empty_background;
		t_window_ptr				    highlight_border;
		t_window_ptr					normal_border;
		t_window_ptr                    move_background;
		t_bitmap_window_ptr				move_bar;
		t_window_ptr                    move_clipper;
		t_bitmap_layer_cache_window_ptr portrait;
		t_window_ptr                    strength_background;
		t_bitmap_window_ptr			    strength_bar;
		t_window_ptr                    strength_clipper;
	};

	t_bitmap_group_ptr					m_bitmaps;
	bool								m_hide_unused;
	std::vector<t_item>					m_items;
	t_army_array_ptr					m_armies;
	int									m_first_army;
	t_army_list_window_limit_handler	m_limit_handler;
	int									m_selected_army;
	t_army_select_handler				m_select_handler;
	t_army_select_handler				m_double_click_handler;
	t_scrollbar_ptr						m_scrollbar;
};

inline void t_army_list_window::set_select_handler( t_army_select_handler handler )
{
	m_select_handler = handler;
}

inline void t_army_list_window::set_limit_handler( t_army_list_window_limit_handler handler )
{
	m_limit_handler = handler;
}

inline void t_army_list_window::set_double_click_handler( t_army_select_handler handler )
{
	m_double_click_handler = handler;
}

inline int t_army_list_window::get_num_rings()
{
	return m_items.size();
}

inline int t_army_list_window::get_num_armies()
{
	if (m_armies)
		return m_armies->size();
	else
		return 0;
}

inline void t_army_list_window::move_list( int step_size )
{
	set_first_visible( m_first_army + step_size );
}

#endif // ARMY_LIST_WINDOW_H_INCLUDED
